package com.cat.dataStructure03;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/contest/tianchi2022/problems/8KXuKl/
 * @create 2025/11/16 19:00
 * @since JDK17
 */

public class Solution72 {
    int[][] dire = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    public int getLength(String[] grid) {
        int n = grid.length, m = grid[0].length(), ans = 0, x = 0, y = 0, d = 0;
        while (x >= 0 && x < n && y >= 0 && y < m) {
            ans++;
            if (grid[x].charAt(y) == 'L') {
                d ^= 2;
            } else if (grid[x].charAt(y) == 'R') {
                d ^= 3;
            }
            x += dire[d][0];
            y += dire[d][1];
        }

        return ans;
    }
}
